#include "Pool.h"
#include "GLPrimitives.h"
#include "GameWorld.h"
#include "General Utils.hpp"

// ===================== Constructors ===========================
Pool::Pool():m_Boundaries()
{}

Pool::Pool(GameRectangle rect): m_Boundaries(rect)
{}


// ===================== Merge test functions ===================================================

bool Pool::CanMergeFromBottom(const Pool& pool)
{
	return (pool.m_Boundaries.x1 == m_Boundaries.x1 && 
			pool.m_Boundaries.x2 == m_Boundaries.x2 &&
			pool.m_Boundaries.y1 == m_Boundaries.y2);
}

bool Pool::CanMergeFromLeft(const Pool& pool)
{
	return (pool.m_Boundaries.y1 == m_Boundaries.y1 &&
			pool.m_Boundaries.y2 == m_Boundaries.y2 &&
			pool.m_Boundaries.x2 == m_Boundaries.x1);
}

bool Pool::CanMergeFromRight(const Pool& pool)
{
	return (pool.m_Boundaries.y1 == m_Boundaries.y1 &&
			pool.m_Boundaries.y2 == m_Boundaries.y2 &&
			pool.m_Boundaries.x1 == m_Boundaries.x2);
}

bool Pool::CanMergeFromTop(const Pool& pool)
{
	return (pool.m_Boundaries.x1 == m_Boundaries.x1 &&
			pool.m_Boundaries.x2 == m_Boundaries.x2 &&
			pool.m_Boundaries.y2 == m_Boundaries.y1);
}

bool Pool::CanMerge(const Pool& pool)
{
	return (CanMergeFromBottom(pool) ||
			CanMergeFromLeft(pool) ||
			CanMergeFromRight(pool) ||
			CanMergeFromTop(pool));
}

// ======================= Render ==========================
// Draws the m_Boundaries rectangle
void Pool::RenderBox()
{
	DrawPrimitives->DrawRectangle(m_Boundaries.x1 - ClipPlane->GetX(), m_Boundaries.y1 - ClipPlane->GetY(),
									m_Boundaries.x2 - ClipPlane->GetX(), m_Boundaries.y2 - ClipPlane->GetY(), black);
}

// =================== Location =========================
// Returns the location of the top left corner of the pool

Vector2D Pool::Location()
{
	return Vector2D(m_Boundaries.x,m_Boundaries.y);
}

bool Pool::IntersectsPool(GameRectangle rect)
{
	return Intersects(rect, m_Boundaries);
}